package warmachineroster.ui.views;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IPartService;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.part.ViewPart;

public class TestView extends ViewPart implements ISelectionListener, IPartListener {
	public TestView() {
	}

	private FormToolkit toolkit;
	private ScrolledForm form;
//	private RssSectionPart section;
	 
	   /**
	    * This is a callback that will allow us
	    * to create the viewer and initialize it.
	    */
	   public void createPartControl(Composite parent) {
	      toolkit = new FormToolkit(parent.getDisplay());
	      form = toolkit.createScrolledForm(parent);
	      form.setText("Hello, Eclipse Forms");
	      FillLayout layout = new FillLayout();
          form.getBody().setLayout(layout);
          getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
//          section = new RssSectionPart(form.getBody(), toolkit, Section.DESCRIPTION|Section.TITLE_BAR|
//        		  Section.TWISTIE|Section.EXPANDED);
          IPartService service = (IPartService) getSite().getService(IPartService.class);
          service.addPartListener(this);
	   }
	 
	   /**
	    * Passing the focus request to the form.
	    */
	   public void setFocus() {
	      form.setFocus();
	   }
	 
	   /**
	    * Disposes the toolkit.
	    */
	   public void dispose() {
	      toolkit.dispose();
	      IPartService service = (IPartService) getSite().getService(IPartService.class);
	      service.removePartListener(this);
	      super.dispose();
	   }

	@Override
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
//		form.setText("part: " + part + " selection: " + selection);
		
	}

	@Override
	public void partActivated(IWorkbenchPart part) {
		form.setText("part Activated: " + part.getTitle());
		
	}

	@Override
	public void partBroughtToTop(IWorkbenchPart part) {
		form.setText("part BroughtToTop: " + part.getTitle());
		
	}

	@Override
	public void partClosed(IWorkbenchPart part) {
		form.setText("part Closed: " + part.getTitle());
		
	}

	@Override
	public void partDeactivated(IWorkbenchPart part) {
		form.setText("part Deactivated: " + part.getTitle());
		
	}

	@Override
	public void partOpened(IWorkbenchPart part) {
		form.setText("part Opened: " + part.getTitle());
		
	}

	   
//	   public RssSectionPart getSection(){
//		   return section;
//	   }


}
